package database;
import database.employee.tb_employee;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import static database.GUI.GUI;

public class EmployeeInfoPanel {
    private JLabel EnameLabel;
    private JLabel EidLabel;
    private JLabel ElevelLabel;
    private JLabel EtelphoneLable;
    private JLabel otherLabel;
    private JButton logoutButton;
    JFrame frameAccount;

    public EmployeeInfoPanel(tb_employee loggedInEmployee) {
        frameAccount = new JFrame();
        frameAccount.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        frameAccount.setSize(400, 300);
        frameAccount.setLocationRelativeTo(null); // 居中显示
        JPanel panel = new JPanel(new GridLayout(6, 1));
        frameAccount.add(panel);

        // 创建标签显示员工姓名和编号
        JLabel EnameLabel = new JLabel("姓名: " + loggedInEmployee.getEname());
        JLabel EidLabel = new JLabel("员工编号: " + loggedInEmployee.getEid());
        JLabel ElevelLabel = new JLabel("员工级别: " + loggedInEmployee.getElevel());
        JLabel EtelphoneLabel = new JLabel("员工电话: " + loggedInEmployee.getEtelPhone());
        JLabel otherLabel = new JLabel("备注: " + loggedInEmployee.getOther());

        panel.add(EnameLabel);
        panel.add(EidLabel);
        panel.add(ElevelLabel);
        panel.add(EtelphoneLabel);
        panel.add(otherLabel);

        JButton btnLogout = new JButton("退出登录");
        panel.add(btnLogout);

        btnLogout.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                frameAccount.dispose();// 关闭当前窗口
                GUI(loggedInEmployee);
                JOptionPane.showMessageDialog(frameAccount, "您已成功退出登录。", "提示", JOptionPane.INFORMATION_MESSAGE);

            }
        });

        frameAccount.setVisible(true);
    }




    private void logout() {
        JOptionPane.showMessageDialog(frameAccount, "您已成功退出登录。", "提示", JOptionPane.INFORMATION_MESSAGE);
        tb_employee emp=new tb_employee();
        SwingUtilities.invokeLater(() -> GUI(emp));
    }
}



